var Adv_skd=require("./Adv_skd")

var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2pvzChannel = require("pvzChannel");
var $2BundleManager = require("BundleManager");
var $2PlantMgr = require("PlantMgr");
var $2UIManager = require("UIManager");
var $2UserDataManager = require("UserDataManager");
var $2TaSdk = require("TaSdk");
var $2MenuUI = require("MenuUI");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_OnlineRewardUI = /* */function (_cc$Component54) {
  babel_inherits(g, _cc$Component54);
  var _super58 = babel_createSuper(g);
  function g() {
    var _this124;
    babel_classCallCheck(this, g);
    _this124 = _super58.apply(this, arguments);
    _this124.video1 = null;
    _this124.onlineInfo = [];
    _this124.timePos = [-225, 0, 225];
    return _this124;
  }
  babel_createClass(g, [{
    key: "onLoad",
    value: function onLoad() {
        Adv_skd.default.instance.hideAllAdv();
                  Adv_skd.default.instance.showInterstitialAd();
                  Adv_skd.default.instance.showGridAdRight();
                  Adv_skd.default.instance.showGridAdLeft();

      var _this125 = this;
      $2TaSdk.default.instance.postEvent("System", {
        system: "在线礼包"
      });
      this.bg = this.node.getChildByName("Bg");
      this.rewardUI = this.node.getChildByName("RewardUI");
      this.plantCard = this.bg.getChildByName("PlantCard");
      this.initPlantInfo();
      this.initTitle();
      $2UserDataManager.default.instance.onlineNum <= 2 && this.schedule(function () {
        _this125.initTitle();
      }, 1);
    }
  }, {
    key: "initTitle",
    value: function initTitle() {
      if ($2UserDataManager.default.instance.onlineNum <= 2) {
        if ($2UserDataManager.default.instance.onlineTime >= 300) {
          this.bg.getChildByName("Time").active = false;
          this.plantCard.children[$2UserDataManager.default.instance.onlineNum].getChildByName("Red").active = true;
        } else {
          this.bg.getChildByName("Time").active = true;
        }
        var _e64 = Math.floor((300 - $2UserDataManager.default.instance.onlineTime) / 60);
        var _t34 = Math.floor(300 - $2UserDataManager.default.instance.onlineTime - 60 * _e64);
        _e64 = "0" + _e64;
        _t34 < 10 && (_t34 = "0" + _t34);
        this.bg.getChildByName("Time").getComponentInChildren(cc.Label).string = _e64 + ":" + _t34;
      } else {
        this.bg.getChildByName("Time").active = false;
      }
    }
  }, {
    key: "initPlantInfo",
    value: function initPlantInfo() {
      var _this126 = this;
      this.bg.getChildByName("Time").x = this.timePos[$2UserDataManager.default.instance.onlineNum];
      var _loop4 = function _loop4(_e65) {
        _this126.onlineInfo.push($2UserDataManager.default.instance.onlineInfo[_e65]);
        var t = $2UserDataManager.default.instance.onlineInfo[_e65].id;
        if (1 == _this126.onlineInfo[_e65].type || 2 == _this126.onlineInfo[_e65].type || 4 == _this126.onlineInfo[_e65].type) {
          _this126.plantCard.children[_e65].getChildByName("AwardPanel").getChildByName("Icon").active = true;
          _this126.plantCard.children[_e65].getChildByName("AwardPanel").getChildByName("Plant").active = false;
          _this126.plantCard.children[_e65].getChildByName("AwardPanel").getChildByName("Icon").getComponentInChildren(cc.Label).string = "X" + _this126.onlineInfo[_e65].num;
          if (4 == _this126.onlineInfo[_e65].type) {
            _this126.plantCard.children[_e65].getChildByName("AwardPanel").getChildByName("Icon").getComponentInChildren(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "PlantIcon/p_" + _this126.onlineInfo[_e65].id, cc.SpriteFrame);
          } else if (1 == _this126.onlineInfo[_e65].type) {
            _this126.plantCard.children[_e65].getChildByName("AwardPanel").getChildByName("Icon").getComponentInChildren(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a034", cc.SpriteFrame);
          } else {
            _this126.plantCard.children[_e65].getChildByName("AwardPanel").getChildByName("Icon").getComponentInChildren(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a033", cc.SpriteFrame);
          }
        } else {
          _this126.plantCard.children[_e65].getChildByName("AwardPanel").getChildByName("Icon").active = false;
          _this126.plantCard.children[_e65].getChildByName("AwardPanel").getChildByName("Plant").active = true;
          if ($2BundleManager.default.instance.getBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(t).dragonName + "/" + $2PlantMgr.default.instance().getPlant(t).dragonName, sp.SkeletonData)) {
            _this126.plantCard.children[_e65].getChildByName("AwardPanel").getComponentInChildren(sp.Skeleton).skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(t).dragonName + "/" + $2PlantMgr.default.instance().getPlant(t).dragonName, sp.SkeletonData), _this126.plantCard.children[_e65].getChildByName("AwardPanel").getComponentInChildren(sp.Skeleton).setAnimation(0, "daiji", true);
          } else {
            $2BundleManager.default.instance.loadBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(t).dragonName + "/" + $2PlantMgr.default.instance().getPlant(t).dragonName, sp.SkeletonData, function () {
              _this126.plantCard.children[_e65].getChildByName("AwardPanel").getComponentInChildren(sp.Skeleton).skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(t).dragonName + "/" + $2PlantMgr.default.instance().getPlant(t).dragonName, sp.SkeletonData);
              _this126.plantCard.children[_e65].getChildByName("AwardPanel").getComponentInChildren(sp.Skeleton).setAnimation(0, "daiji", true);
            });
          }
        }
        if (_this126.onlineInfo[_e65].get) {
          _this126.plantCard.children[_e65].getChildByName("Mask").active = true;
          _this126.plantCard.children[_e65].getChildByName("Tip").active = true;
          _this126.plantCard.children[_e65].getChildByName("Red").active = false;
        } else {
          _this126.plantCard.children[_e65].getChildByName("Tip").active = false;
          if (_e65 > $2UserDataManager.default.instance.onlineNum) {
            _this126.plantCard.children[_e65].getChildByName("Mask").active = true, _this126.plantCard.children[_e65].getChildByName("Red").active = false;
          } else {
            _this126.plantCard.children[_e65].getChildByName("Mask").active = false;
          }
        }
      };
      for (var _e65 = 0; _e65 < 3; _e65++) {
        _loop4(_e65);
      }
    }
  }, {
    key: "onClickGetReward",
    value: function onClickGetReward() {
      this.getReward();
      this.onlineInfo[$2UserDataManager.default.instance.onlineNum].get = true;
      $2UserDataManager.default.instance.onlineNum++;
      $2UserDataManager.default.instance.onlineTime = 0;
      this.initPlantInfo();
      this.initTitle();
      this.node.getChildByName("RewardUI").active = false;
    }
  }, {
    key: "getReward",
    value: function getReward() {
      if (1 == this.onlineInfo[$2UserDataManager.default.instance.onlineNum].type) {
        $2UserDataManager.default.instance.gold += this.onlineInfo[$2UserDataManager.default.instance.onlineNum].num;
      } else if (2 == this.onlineInfo[$2UserDataManager.default.instance.onlineNum].type) {
        $2UserDataManager.default.instance.diamond += this.onlineInfo[$2UserDataManager.default.instance.onlineNum].num;
      } else if (4 == this.onlineInfo[$2UserDataManager.default.instance.onlineNum].type) {
        $2UserDataManager.default.instance.setPlantChip(this.onlineInfo[$2UserDataManager.default.instance.onlineNum].id, $2UserDataManager.default.instance.diamond += this.onlineInfo[$2UserDataManager.default.instance.onlineNum].num);
      } else {
        $2UserDataManager.default.instance.getPlant(this.onlineInfo[$2UserDataManager.default.instance.onlineNum].id);
      }
    }
  }, {
    key: "onClickCard",
    value: function onClickCard(e) {
      var _this127 = this;
      var t = e.currentTarget;
      t.getChildByName("Red").opacity = 0;
      t.getComponent(cc.Animation).play();
      t.getComponent(cc.Animation).on("stop", function () {
        _this127.showReward();
      });
    }
  }, {
    key: "showReward",
    value: function showReward() {
      var _this128 = this;
      this.node.getChildByName("RewardUI").active = true;
      if (1 == this.onlineInfo[$2UserDataManager.default.instance.onlineNum].type || 2 == this.onlineInfo[$2UserDataManager.default.instance.onlineNum].type || 4 == this.onlineInfo[$2UserDataManager.default.instance.onlineNum].type) {
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantAni").active = false;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Icon").active = true;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Icon").getComponentInChildren(cc.Label).string = "X" + this.onlineInfo[$2UserDataManager.default.instance.onlineNum].num;
        if (4 == this.onlineInfo[$2UserDataManager.default.instance.onlineNum].type) {
          this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Icon").getComponentInChildren(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "PlantIcon/p_" + this.onlineInfo[$2UserDataManager.default.instance.onlineNum].id, cc.SpriteFrame);
        } else if (1 == this.onlineInfo[$2UserDataManager.default.instance.onlineNum].type) {
          this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Icon").getComponentInChildren(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a034", cc.SpriteFrame);
        } else {
          this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Icon").getComponentInChildren(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a033", cc.SpriteFrame);
        }
      } else {
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantAni").active = true;
        this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("Icon").active = false;
        var _e66 = this.onlineInfo[$2UserDataManager.default.instance.onlineNum].id;
        if ($2UserDataManager.default.instance.plantLock.includes(_e66)) {
          this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantAni").getChildByName("TipLabel").active = true;
        } else {
          this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantAni").getChildByName("TipLabel").active = false;
        }
        if ($2BundleManager.default.instance.getBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(_e66).dragonName + "/" + $2PlantMgr.default.instance().getPlant(_e66).dragonName, sp.SkeletonData)) {
          this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantAni").getComponent(sp.Skeleton).skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(_e66).dragonName + "/" + $2PlantMgr.default.instance().getPlant(_e66).dragonName, sp.SkeletonData);
          this.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantAni").getComponent(sp.Skeleton).setAnimation(0, "daiji", true);
        } else {
          $2BundleManager.default.instance.loadBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(_e66).dragonName + "/" + $2PlantMgr.default.instance().getPlant(_e66).dragonName, sp.SkeletonData, function () {
            _this128.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantAni").getComponent(sp.Skeleton).skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", "plant/" + $2PlantMgr.default.instance().getPlant(_e66).dragonName + "/" + $2PlantMgr.default.instance().getPlant(_e66).dragonName, sp.SkeletonData);
            _this128.node.getChildByName("RewardUI").getChildByName("RewardSingle").getChildByName("PlantAni").getComponent(sp.Skeleton).setAnimation(0, "daiji", true);
          });
        }
      }
      var e = this.node.getChildByName("RewardUI").getChildByName("RewardBtnPanel").children[0];
      if ($2pvzChannel.pvzChannel.instance().channel.indexOf("wx") >= 0 && $2pvzChannel.pvzChannel.instance().getCtrl("p1")) {
        e.active = false;
        this.scheduleOnce(function () {
          e.active = true;
        }, $2pvzChannel.pvzChannel.instance().getCtrl("p1"));
        $2pvzChannel.pvzChannel.instance().getCtrl("p4") && (this.video1.active = false);
      }
    }
  }, {
    key: "onClickVideo",
    value: function onClickVideo() {
      var _this129 = this;
      $2pvzChannel.pvzChannel.instance().showVideo({
        sucCall() {
          _this129.getReward();
          _this129.getReward();
          _this129.onlineInfo[$2UserDataManager.default.instance.onlineNum].get = true;
          $2UserDataManager.default.instance.onlineNum++;
          $2UserDataManager.default.instance.onlineTime = 0;
          _this129.node.getChildByName("RewardUI").active = false;
          _this129.initPlantInfo();
          _this129.initTitle();
        },
        failCall() {},
        endCall() {}
      });
    }
  }, {
    key: "onClickCloseBtn",
    value: function onClickCloseBtn() {
      Adv_skd.default.instance.hideAllAdv();
      
      $2UIManager.default.instance.closeUI("OnlineRewardUI");
      $2UIManager.default.instance.uiList.MenuUI.getComponent($2MenuUI.default).showNode();
    }
  }]);
  return g;
}(cc.Component);
cc__decorate([ccp_property(cc.Node)], def_OnlineRewardUI.prototype, "video1", undefined);
def_OnlineRewardUI = cc__decorate([ccp_ccclass], def_OnlineRewardUI);
exports.default = def_OnlineRewardUI;